package ylg.com.cn.youtube.main.fragment_home;

import java.util.List;

import ylg.com.cn.youtube._data.Video;
import ylg.com.cn.youtube._data.source.VideoDataSource;
import ylg.com.cn.youtube._data.source.remote.VideoRemoteDataSource;

/**
 * Created by MyPC on 2017/1/11.
 */
public class HomePagePresenter implements HomePageContract.Presenter {

    public String TAG = HomePagePresenter.class.getName();

    private final HomePageContract.View view;
    private final VideoRemoteDataSource model;

    public HomePagePresenter(HomePageContract.View view, VideoRemoteDataSource model) {
        this.view = view;
        this.model = model;
    }

    @Override
    public void loadVideos() {
        view.showVideosLoadingOnGoing(); // 让fragment 显示正在获取数据的效果
        int lastVideo = 0;
        model.getHomePageVideos("", lastVideo, new VideoDataSource.GetVideosCallBack() {

            @Override
            public void onVideoLoaded(List<Video> data) {
                view.showVideoList(data);
                view.showVideosLoadingComplete(); // 让fragment 显示数据加载好。
            }

            @Override
            public void onDataNotAvailable(String message) {
                view.showEmptyVideoError();
            }

        });

    }

    @Override
    public void loadVideosFrom(int id) {
        int lastVideo = id;
        model.getHomePageVideos("", lastVideo, new VideoDataSource.GetVideosCallBack() {

            @Override
            public void onVideoLoaded(List<Video> data) {
                view.appendVideosToList(data);
                view.showVideosLoadingComplete(); // 让fragment 显示数据加载好。
            }

            @Override
            public void onDataNotAvailable(String message) {
                view.showEmptyVideoError();
            }

        });
    }

    @Override
    public void start() {

    }
}
